<template>
    <div>
        <el-table
                ref="table"
                :data="tableData"
                stripe
                v-loading="loading"
                border
                height="800"
                style="width: 100%">
            <el-table-column
                    type="selection"
                    align="center"
                    fixed="left"
                    width="40">
            </el-table-column>

            <el-table-column
                    type="index"
                    :index="tableIndex"
                    align="center"
                    fixed="left"
                    width="60">
            </el-table-column>

            <el-table-column
                    align="center"
                    property="batName"
                    width="150"
                    label="bat文件名称">
            </el-table-column>

            <el-table-column
                    align="center"
                    property="batPath"
                    width="200"
                    label="bat文件路径">
            </el-table-column>

            <el-table-column
                    align="center"
                    width="200"
                    property="checkBatUrl"
                    label="远程监控是否启动成功url">
            </el-table-column>
            
            <el-table-column
                align="center"
                width="150"
                property="isOpen"
                label="是否成功运行中">
            </el-table-column>


            <el-table-column
                    align="center"
                    property="comment"
                    label="注释">
            </el-table-column>

            <el-table-column
                    sortable
                    property="createTime"
                    align="center"
                    width="150"
                    label="创建日期">
                <template slot-scope="scope">
                    {{ scope.row.createTime | datetimeFormat}}
                </template>
            </el-table-column>

            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="100">
                <template slot-scope="scope">
                    <el-button type="text" size="small" @click="isOpenHandle(scope.row)">启动</el-button>
                    <el-button type="text" size="small" @click="deleteHandle(scope.row)">删除</el-button>
                </template>
            </el-table-column>

        </el-table>

        <div class="pagination">
            <el-pagination
                    @current-change="currentChangeHandle"
                    :page-size="pageSize"
                    layout="total, prev, pager, next"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';

    /**
     *  日志列表
     * @author yangjunxiong
     * @date 2019/7/29 17:21.
     */
    export default {
        name: 'LogbackLogTable',
        mounted() {
            this.loadData();
        },
        components: {
        },
        props: {
            searchParam: {
                type: Object,
                default() {
                    return {}
                }
            }
        },
        data() {
            return {
                total: 0,
                pageSize: 10,
                pageNo: 1,
                logId: undefined,
                loading: false,
                tableData: [],
                messageDetail: {},   //消息详情
            }
        },
        computed: {},
        methods: {
            /**
             * 表格索引排序
             * @author yangjunxiong
             * @date 2019/3/7 17:09
             */
            tableIndex(index) {
                if (this.pageNo <= this.total / this.pageSize) {
                    return index + this.pageSize * (this.pageNo - 1) + 1;
                }
                //重新调整当前页面重新调整
                if (this.total % this.pageSize === 0) {
                    this.pageNo = parseInt(this.total / this.pageSize);
                } else {
                    this.pageNo = parseInt(this.total / this.pageSize) + 1;
                }

                return index + this.pageSize * (this.pageNo - 1) + 1;
            },
            loadData: function (filter) {
                let params = Object.assign(this.searchParam, {
                    page: this.pageNo,
                    limit: this.pageSize
                }, filter);
                this.loading = true;

                this.$ajax.get("run_bat/paging", {
                    params: params
                }).then(res => {
                    this.loading = false;
                    if (res.code !== 0) {
                        this.$message.error(res.msg);
                        return;
                    }
                    this.tableData = res.data;
                    this.total = res.count;
                });

            },
            /**
             * 分页
             */
            currentChangeHandle(val) {
                this.pageNo = val;
                this.loadData();
            },
            /**
             * 【 条件批量删除 】
             **/
            selectionChangeHandlePQuery() {
                this.$ajax.delete('logback/sync_delete_query', {
                    params: this.searchParam
                }).then(res => {
                    if (res.code === 0) {
                        // this.$message.success(res.msg);
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            },
            /**
             * 根据主键删除
             */
            deleteHandle(row) {
                this.$ajax.delete('logback/sync/' + row.id).then(res => {
                    if (res.code === 0) {
                        this.stackDialogVisible = false;
                        this.loadData();
                        this.$emit('deleteSuccess', row.id);
                    } else {
                        this.$message.error(res.msg);
                    }
                });
            },
            //启动项目
            isOpenHandle(row){

            }
        },
        watch: {},
        filters: {},
        beforeDestroy() {

        }
    }
</script>

<style scoped>

</style>